﻿using System;
using System.Xml;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Rsc;

namespace Aulac.Rsc.Ems
{
    /// <summary>
    /// Thông tin tùy chọn hệ thống
    /// </summary>
	public class Options
	{

        /// <summary>
        /// Khởi tạo
        /// </summary>
		public Options(){
            
		}
        /// <summary>
        /// Khởi tạo
        /// </summary>
        /// <param name="IsCommaSeperate"></param>
        /// <param name="IsUserMngtID"></param>
        /// <param name="IsDayMonth"></param>
        /// <param name="IsUseConvertUnit"></param>
        /// <param name="AllowOverOnhand"></param>
        /// <param name="pMethodInstockOnhand"></param>
        /// <param name="DecimalRound"></param>
        /// <param name="DecimalRoundReport"></param>
        /// <param name="RoundNumReport"></param>
        public Options(bool IsCommaSeperate, bool IsUserMngtID, bool IsDayMonth, bool IsUseConvertUnit, bool AllowOverOnhand, Aulac.Rsc.MethodInstockOnhands pMethodInstockOnhand, int DecimalRound, int DecimalRoundReport, int RoundNumReport)
		{
			this.IsCommaSeperate =	IsCommaSeperate;
			this.IsUserMngtID =		IsUserMngtID;	
			this.IsDayMonth =		IsDayMonth ;		
			this.IsUseConvertUnit = IsUseConvertUnit;
			this.AllowOverOnhand =	AllowOverOnhand;	
			this.MethodInstockOnhand =		pMethodInstockOnhand;	
			this.DecimalRound =		DecimalRound;
			this.DecimalRoundReport =DecimalRoundReport;
			this.RoundNumReport    =	RoundNumReport;
		}
		/// <summary>
		/// Khởi tạo
		/// </summary>
		/// <param name="nOptions"></param>
        public Options(XmlNode nOptions)
		{
			SetOptions(nOptions);
		}


		#region Variables Declarative

		public bool IsCommaSeperate = true;
        public bool IsUserMngtID = false;
		public bool IsDayMonth = false;
        public bool IsUseConvertUnit = false;
        /// <summary>
        /// Cho phep xuat qua luong ton
        /// </summary>
		public bool AllowOverOnhand = false;
        public DateTime ServerDate = DateTime.Now;

        /// <summary>
        /// Phuong thuc ton kho
        /// </summary>
        public Aulac.Rsc.MethodInstockOnhands MethodInstockOnhand = MethodInstockOnhands.CurrentAvg;
		public string Language = "";
		public int DecimalRound = 0; 
		public int 	DecimalRoundReport = 0;
        public int RoundNumReport = 0;
		
		#region static

		#endregion
		#endregion
        /// <summary>
        /// Get DateFormats
        /// </summary>
        public Aulac.Global.Enums.DateFormats DateFormat
        {
            get {
                return (IsDayMonth)? Aulac.Global.Enums.DateFormats.dd_MM_yyyy : Aulac.Global.Enums.DateFormats.MM_dd_yyyy;
            }
        }
		#region Public methods
		/// <summary>
		/// 
		/// </summary>
		/// <param name="nOptions"></param>
        public void SetOptions(XmlNode nOptions){
			try
			{
				if (null == nOptions)
					return;

				XmlElement eOptions = (XmlElement)nOptions;
                ServerDate = XmlProcess.GetValueDateTimeAtrb(eOptions, tagOption.SystemDate, DateFormat);

                IsCommaSeperate = XmlProcess.GetValueBooleanAtrb(eOptions, tagOption.IsCommaSeperate);
                IsUserMngtID = XmlProcess.GetValueBooleanAtrb(eOptions, tagOption.IsUserMngtID);
                IsDayMonth = XmlProcess.GetValueBooleanAtrb(eOptions, tagOption.IsDayMonth);
                IsUseConvertUnit = XmlProcess.GetValueBooleanAtrb(eOptions, tagOption.IsUseConvertUnit);
                AllowOverOnhand = XmlProcess.GetValueBooleanAtrb(eOptions, tagOption.AllowOverOnhand);

                MethodInstockOnhand = (MethodInstockOnhands)ValueHelper.ChangeType( XmlProcess.GetValueAtrb(eOptions, tagOption.MethodOnHand),typeof(MethodInstockOnhands));
                DecimalRound = (int)XmlProcess.GetValueDoubleAtrb(eOptions, tagOption.DecimalRound);
                DecimalRoundReport = (int)XmlProcess.GetValueDoubleAtrb(eOptions, tagOption.DecimalRoundReport);
                RoundNumReport = (int)XmlProcess.GetValueDoubleAtrb(eOptions, tagOption.RoundReportNumber);
                Language = XmlProcess.GetValueAtrb(eOptions, tagOption.LanguageView);
			}
			catch{}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="nParent"></param>
        public void AddOptionInfo(ref XmlElement nParent)
		{
			try
			{
				XmlProcess.SetAtrb(ref nParent,
                    new string[]{tagOption.IsCommaSeperate,
									tagOption.IsUserMngtID,
									tagOption.IsDayMonth,
									tagOption.IsUseConvertUnit,
									tagOption.AllowOverOnhand,
									tagOption.MethodOnHand,							
									tagOption.DecimalRound,
									tagOption.DecimalRoundReport,
									tagOption.RoundReportNumber,
									tagOption.LanguageView},
					new object[]{IsCommaSeperate,
									IsUserMngtID,
									IsDayMonth,
									IsUseConvertUnit,
									AllowOverOnhand,
									MethodInstockOnhand,
									DecimalRound, 
									DecimalRoundReport, 
									RoundNumReport,
									Language});
			}
			catch(Exception ex){
				throw ex;
			}
		}
		#endregion
        /// <summary>
        /// tag Option
        /// </summary>
        public class tagOption
        {
            public const string OPTIONS = "OPTIONS";
            public const string IsCommaSeperate = "IsCommaSeperate";
            public const string IsUserMngtID = "IsUserMngtID";
            public const string IsDayMonth = "IsDayMonth";
            public const string IsUseConvertUnit = "IsUseConvertUnit";
            public const string AllowOverOnhand = "AllowOverOnhand";
            public const string MethodOnHand = "MethodOnHand";

            public const string DecimalRound = "DecimalRound";
            public const string DecimalRoundReport = "DecimalRoundReport";
            public const string LanguageView = "LanguageView";
            public const string RoundReportNumber = "RoundReportNumber";
            public const string SystemDate = "SystemDate";

            public const string DateFormat = "DateFormat";
        }
	}
				
}
